var pathName = window.document.location.pathname;
var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1); 
//下安装 一些公共的
//增加窗帘
function addNewWindow(number) {
	var form = makeFormId(number);
	var rootDiv = $('<div></div>');
	rootDiv.append('<hr>');
	rootDiv.append('<h3>&nbsp;&nbsp;&nbsp;窗帘-' + number + '</h3>');
	rootDiv.append('<input type="hidden" value="' + number
			+ '" name="myNameIsHidden">');
	// 商品图片上传
	rootDiv.append(makeTiTou("商品图片上传:"));
	rootDiv.append(makeOnlyUploadPhoto("goodPictureUpload"));
	// 安装房间
	rootDiv.append(makeTiTou("安装房间:"));
	var bradioFather = makeRadioFather("anzhuangfangjian");
	$.post("../location/queryAllLocation.do", function(data) {
		$.each(data, function(i, install) {
			bradioFather.append(makeRadio("locationId", install.locationId,
					install.locationContent));
		});
		bradioFather.append(makeInput("其他房间", "otherRoom", ""));
	}, "json");
	rootDiv.append(bradioFather);
	// 类型
	rootDiv.append(makeTiTou("类型:"));
	var leixingbradioFather = makeRadioFather("leixing");
	leixingbradioFather.append(makeRadio("type", 0, "布艺窗帘",
			"chooseShadeTypeChange(this)"));
	leixingbradioFather.append(makeRadio("type", 1, "成品帘",
			"chooseShadeTypeChange(this)"));
	rootDiv.append(leixingbradioFather);
	form.append(rootDiv);
	return form;
}

// 选窗帘类型的点击事件
function chooseShadeTypeChange(object) {
	var div = $(object).parent().parent().parent();
	$
			.each(
					div.find("input[name='type']:checked"),
					function(i, ii) {
						if ($(ii).val() == 0) {
							// 这是点击的布帘
							var rootDiv = div.parent();
							rootDiv.children('div[name="leixing"]').nextAll()
									.remove();
							// 结构
							rootDiv.append(makeTiTou("结构:"));
							var jiegoubradioFather = makeRadioFather("jiegou");
							jiegoubradioFather.append(makeRadio("structure", 0,
									"单布", "chooseStruteChange(this)"));
							jiegoubradioFather.append(makeRadio("structure", 1,
									"单纱", "chooseStruteChange(this)"));
							jiegoubradioFather.append(makeRadio("structure", 2,
									"布纱双层", "chooseStruteChange(this)"));
							rootDiv.append(jiegoubradioFather);

						} else if ($(ii).val() == 1) {
							// 这是选择成品帘
							var rootDiv = div.parent();
							rootDiv.children('div[name="leixing"]').nextAll()
									.remove();
							// 成品帘 宽高 安装方式
							rootDiv.append(makeInput("宽", "wide", "米"));
							rootDiv.append(makeInput("高", "high", "米"));
							// 成品帘安装方式
							rootDiv.append(makeTiTou("安装方式:"));
							var anzhuangfangshiradioFather = makeRadioFather("anzhuangfangshi");
							anzhuangfangshiradioFather.append(makeRadio(
									"pinstallSite", 0, "顶装"));
							anzhuangfangshiradioFather.append(makeRadio(
									"pinstallSite", 1, "侧装"));
							rootDiv.append(anzhuangfangshiradioFather);
						}

					});
}
// 结构,单布,单纱,布加纱的点击事件
function chooseStruteChange(object) {
	var div = $(object).parent().parent().parent();
	$.each(div.find("input[name='structure']:checked"), function(i, ii) {
		if ($(ii).val() == 0) {
			// 单布
			var rootDiv = div.parent();
			rootDiv.children('div[name="jiegou"]').nextAll().remove();
			// 里布
			rootDiv.append(makeTiTou("里布:"));
			var liburadioFather = makeRadioFather("libu");
			liburadioFather.append(makeRadio("shadingCloth", 1, "遮光里布", ""));
			liburadioFather.append(makeRadio("shadingCloth", 2, "半遮光里布", ""));
			liburadioFather.append(makeRadio("shadingCloth", 0, "无", ""));
			rootDiv.append(liburadioFather);
			// 款式
			rootDiv.append(makeTiTou("款式:"));
			var kuanshiradioFather = makeRadioFather("kuanshi");
			kuanshiradioFather.append(makeRadio("style", 0, "打孔款",
					"chooseKuanshiChange(this)"));
			kuanshiradioFather.append(makeRadio("style", 1, "韩褶款或挂钩款",
					"chooseKuanshiChange(this)"));
			kuanshiradioFather.append(makeRadio("style", 2, "帘头款",
					"chooseKuanshiChange(this)"));
			rootDiv.append(kuanshiradioFather);
		} else if ($(ii).val() == 1) {
			// 单纱
			var rootDiv = div.parent();
			rootDiv.children('div[name="jiegou"]').nextAll().remove();
			// 款式
			rootDiv.append(makeTiTou("款式:"));
			var kuanshiradioFather = makeRadioFather("kuanshi");
			kuanshiradioFather.append(makeRadio("style", 1, "韩褶款或者挂钩款",
					"chooseKuanshiChange(this)"));
			rootDiv.append(kuanshiradioFather);

		} else if ($(ii).val() == 2) {
			// 布加纱
			var rootDiv = div.parent();
			rootDiv.children('div[name="jiegou"]').nextAll().remove();
			// 里布
			rootDiv.append(makeTiTou("里布:"));
			var liburadioFather = makeRadioFather("libu");
			liburadioFather.append(makeRadio("shadingCloth", 1, "遮光里布", ""));
			liburadioFather.append(makeRadio("shadingCloth", 2, "半遮光里布", ""));
			liburadioFather.append(makeRadio("shadingCloth", 0, "无", ""));
			rootDiv.append(liburadioFather);
			// 款式
			rootDiv.append(makeTiTou("款式:"));
			var kuanshiradioFather = makeRadioFather("kuanshi");
			kuanshiradioFather.append(makeRadio("style", 0, "打孔款",
					"chooseKuanshiChange(this)"));
			kuanshiradioFather.append(makeRadio("style", 1, "韩褶款或挂钩款",
					"chooseKuanshiChange(this)"));
			kuanshiradioFather.append(makeRadio("style", 2, "帘头款",
					"chooseKuanshiChange(this)"));
			rootDiv.append(kuanshiradioFather);
		}
	});
}
// 款式, 结构, 判断增加尺寸输入
function chooseKuanshiChange(object) {
	var div = $(object).parent().parent().parent();
	var lastDiv = div.parentsUntil("form[name='defaultForm']");
	// 打孔
	$
			.each(
					lastDiv.find("input[name='structure']:checked"),
					function(b, bb) {
						if ($(bb).val() == 0) {
							// 单布
							$
									.each(
											div
													.find("input[name='style']:checked"),
											function(a, aa) {
												if ($(aa).val() == 0) {
													var rootDiv = div.parent();
													rootDiv
															.children(
																	'div[name="style"]')
															.nextAll().remove();
													// 尺寸输入 填写布尺寸, 填写纱尺寸, 填写帘头尺寸
													rootDiv
															.append(makeTiTou("尺寸输入:"));
													rootDiv.append(makeButton(
															"bulian",
															"buMoTaiKuang",
															"buClick(this)",
															"填写布尺寸"));
												} else if ($(aa).val() == 1) {
													var rootDiv = div.parent();
													rootDiv
															.children(
																	'div[name="kuanshi"]')
															.nextAll().remove();
													// 尺寸输入 填写布尺寸, 填写纱尺寸, 填写帘头尺寸
													rootDiv
															.append(makeTiTou("尺寸输入:"));
													rootDiv.append(makeButton(
															"bulian",
															"buMoTaiKuang",
															"buClick(this)",
															"填写布尺寸"));
												} else if ($(aa).val() == 2) {
													// 有帘头
													var rootDiv = div.parent();
													rootDiv
															.children(
																	'div[name="kuanshi"]')
															.nextAll().remove();
													// 尺寸输入 填写布尺寸, 填写纱尺寸, 填写帘头尺寸
													rootDiv
															.append(makeTiTou("尺寸输入:"));
													rootDiv.append(makeButton(
															"bulian",
															"buMoTaiKuang",
															"buClick(this)",
															"填写布尺寸"));
													rootDiv
															.append(makeButton(
																	"liantou",
																	"lianTouMotaiKuang",
																	"lianClick(this)",
																	"填写帘头尺寸"));
												}
											});
						} else if ($(bb).val() == 1) {
							// 单纱
							var rootDiv = div.parent();
							rootDiv.children('div[name="kuanshi"]').nextAll()
									.remove();
							// 尺寸输入 填写布尺寸, 填写纱尺寸, 填写帘头尺寸
							rootDiv.append(makeTiTou("尺寸输入:"));
							rootDiv
									.append(makeButton("shalian",
											"shaMoTaiKuang", "shaClick(this)",
											"填写纱尺寸"));
						} else if ($(bb).val() == 2) {
							// 布纱双层
							$
									.each(
											div
													.find("input[name='style']:checked"),
											function(a, aa) {
												if ($(aa).val() == 0) {
													var rootDiv = div.parent();
													rootDiv
															.children(
																	'div[name="kuanshi"]')
															.nextAll().remove();
													// 安装情况
													rootDiv
															.append(makeTiTou("安装情况:"));
													var kuanshiradioFather = makeRadioFather("anzhuangqingkuang");
													kuanshiradioFather
															.append(makeRadio(
																	"installCase",
																	1,
																	"布纱相同位置安装",
																	"anzhuangqingkuangChange(this)"));
													kuanshiradioFather
															.append(makeRadio(
																	"installCase",
																	0,
																	"布纱分开安装",
																	"anzhuangqingkuangChange(this)"));
													rootDiv
															.append(kuanshiradioFather);
												} else if ($(aa).val() == 1) {
													var rootDiv = div.parent();
													rootDiv
															.children(
																	'div[name="kuanshi"]')
															.nextAll().remove();
													// 安装情况
													rootDiv
															.append(makeTiTou("安装情况:"));
													var kuanshiradioFather = makeRadioFather("anzhuangqingkuang");
													kuanshiradioFather
															.append(makeRadio(
																	"installCase",
																	1,
																	"布纱相同位置安装",
																	"anzhuangqingkuangChange(this)"));
													kuanshiradioFather
															.append(makeRadio(
																	"installCase",
																	0,
																	"布纱分开安装",
																	"anzhuangqingkuangChange(this)"));
													rootDiv
															.append(kuanshiradioFather);
												} else if ($(aa).val() == 2) {
													// 有帘头
													var rootDiv = div.parent();
													rootDiv
															.children(
																	'div[name="kuanshi"]')
															.nextAll().remove();
													// 安装情况
													rootDiv
															.append(makeTiTou("安装情况:"));
													var kuanshiradioFather = makeRadioFather("anzhuangqingkuang");
													kuanshiradioFather
															.append(makeRadio(
																	"installCase",
																	1,
																	"布纱相同位置安装",
																	"anzhuangqingkuangChange(this)"));
													kuanshiradioFather
															.append(makeRadio(
																	"installCase",
																	0,
																	"布纱分开安装",
																	"anzhuangqingkuangChange(this)"));
													rootDiv
															.append(kuanshiradioFather);

												}
											});
						}
					});

}
// 布纱相同位置安装, 或者不同位置安装点击事件
function anzhuangqingkuangChange(object) {
	var par = $(object).parentsUntil("form");
	var installCaseVal = par.find('input[name="installCase"]:checked').val();
	var kuanshiVal = par.find('input[name="style"]:checked').val();
	var par2 = $(object).parent().parent().parent().parent();
	$(object).parent().parent().parent().nextAll('div').remove();
	if (installCaseVal == 1) {
		// 相同位置安装
		if (kuanshiVal == 0) {
			par2.append(makeTiTou("尺寸输入:"));
			par2.append(makeButton("bulian", "chicunMoTaiKuang",
					"chicunClick(this)", "填写尺寸"));
		} else if (kuanshiVal == 1) {
			par2.append(makeTiTou("尺寸输入:"));
			par2.append(makeButton("bulian", "chicunMoTaiKuang",
					"chicunClick(this)", "填写尺寸"));
		} else if (kuanshiVal == 2) {
			// 帘头款
			par2.append(makeTiTou("尺寸输入:"));
			par2.append(makeButton("bulian", "chicunMoTaiKuang",
					"chicunClick(this)", "填写尺寸"));
			par2.append(makeButton("liantou", "lianTouMotaiKuang",
					"lianClick(this)", "填写帘头尺寸"));
		}
	} else if (installCaseVal == 0) {
		// 不同位置安装
		if (kuanshiVal == 0) {
			par2.append(makeTiTou("尺寸输入:"));
			par2.append(makeButton("bulian", "buMoTaiKuang", "buClick(this)",
					"填写布尺寸"));
			par2.append(makeButton("shalian", "shaMoTaiKuang",
					"shaClick(this)", "填写纱尺寸"));
		} else if (kuanshiVal == 1) {
			par2.append(makeTiTou("尺寸输入:"));
			par2.append(makeButton("bulian", "buMoTaiKuang", "buClick(this)",
					"填写布尺寸"));
			par2.append(makeButton("shalian", "shaMoTaiKuang",
					"shaClick(this)", "填写纱尺寸"));
		} else if (kuanshiVal == 2) {
			// 帘头款
			// 尺寸输入 填写布尺寸, 填写纱尺寸, 填写帘头尺寸
			par2.append(makeTiTou("尺寸输入:"));
			par2.append(makeButton("bulian", "buMoTaiKuang", "buClick(this)",
					"填写布尺寸"));
			par2.append(makeButton("shalian", "shaMoTaiKuang",
					"shaClick(this)", "填写纱尺寸"));
			par2.append(makeButton("liantou", "lianTouMotaiKuang",
					"lianClick(this)", "填写帘头尺寸"));
		}
	}

}

// 布帘安装方式点击事件(顶装侧装点击事件)
function anzhuangfangshiChange(object) {
	$.each(
					$(object).parentsUntil(".modal-body").find(
							'input[name="hiddenInput"]'),
					function(i, input) {
						if (i == 0) {
							var context = $(input).val();
							var formContext = $("#" + context).serialize();
							// 数据整理
							formContext = decodeURIComponent(formContext, true);
							var img;
							$.each($("#" + context).find("img"), function(aa,
									image) {
								img = $(image).attr("src");
							});
							formContext = updateString(formContext);
							formContext = JSON.parse(formContext);
							formContext.goodsPicture = img;
							sentContext = formContext;
							var one2 = JSON.stringify(formContext);
							// 在得到当前form提交的数据
							var sunContext = $("form[name='" + context + "']")
									.serialize();
							sunContext = decodeURIComponent(sunContext, true);
							var two2 = updateString(sunContext);
							sunContext = JSON.parse(updateString(sunContext));
							// sentContext, 根据这得到需不需要再加一项
							if (sentContext.structure == 2) {
								if (sentContext.installCase == 1) {
									// 布纱相同位置安装
									var anzhuangshiDiv = $(object).parent()
											.parent().parent();
									var rootDiv = $(object).parent().parent()
											.parent().parent();
									if (rootDiv
											.find("div[name='peijianpeishian']").length < 1) {
										var cradioFather = makeRadioFather("peijianpeishian");
										cradioFather.append(makeRadio("addAcc",
												0, "顶装单安装码",
												"peijianAccChange(this)"));
										cradioFather.append(makeRadio("addAcc",
												1, "顶装双支架",
												"peijianAccChange(this)"));
										anzhuangshiDiv
												.after(makeTiTou("配件配饰安装:"));
										anzhuangshiDiv.next("div").after(
												cradioFather);
									}
								} else {
									// TODO 检测一下是否都勾选
									$
											.post(
													"../taskManage/getInstallAccByChoose.do",
													{
														one : one2,
														two : two2
													},
													function(data) {
														var root2 = $(object)
																.parent()
																.parent()
																.parent()
																.next();
														var cradioFather = makeRadioFather("peijianpeijian");
														var div = $('<div class="radio-inline"></div>');
														var lableInput = $('<label>'
																+ data
																+ '<input type="hidden" name="panzhuangfangshi" value="'
																+ data
																+ '"></lable>');
														div.append(lableInput);
														cradioFather
																.append(div);
														var rootDiv = $(object)
																.parent()
																.parent()
																.parent()
																.parent();
														if (rootDiv
																.find('div[name="peijianpeijian"]').length > 0) {
															$
																	.each(
																			rootDiv
																					.find('div[name="peijianpeijian"]'),
																			function(
																					aa,
																					cc) {
																				$(
																						cc)
																						.remove();
																			});
														}
														root2
																.after(cradioFather);
													}, "json");
								}
							} else {
								// 这些是单布单纱的时候

								$.post(
												"../taskManage/getInstallAccByChoose.do",
												{
													one : one2,
													two : two2
												},
												function(data) {
													var root2 = $(object)
															.parent().parent()
															.parent().next();
													var cradioFather = makeRadioFather("peijianpeijian");
													var div = $('<div class="radio-inline"></div>');
													var lableInput = $('<label>'
															+ data
															+ '<input type="hidden" name="panzhuangfangshi" value="'
															+ data
															+ '"></lable>');
													div.append(lableInput);
													cradioFather.append(div);
													var rootDiv = $(object)
															.parent().parent()
															.parent().parent();
													if (rootDiv
															.find('div[name="peijianpeijian"]').length > 0) {
														$
																.each(
																		rootDiv
																				.find('div[name="peijianpeijian"]'),
																		function(
																				aa,
																				cc) {
																			$(
																					cc)
																					.remove();
																		});
													}
													root2.after(cradioFather);
												}, "json");

							}

						}
					});

}
// 就是根据布纱双层, 配件配饰选择事件
function peijianAccChange(object) {
	// 安装配件选项
	$.each($(object).parentsUntil(".modal-body").find(
			'input[name="hiddenInput"]'), function(i, input) {
		if (i == 0) {
			var context = $(input).val();
			var formContext = $("#" + context).serialize();
			// 数据整理
			formContext = decodeURIComponent(formContext, true);
			var img;
			$.each($("#" + context).find("img"), function(aa, image) {
				img = $(image).attr("src");
			});
			var sentContext = formContext + "&goodsPicture=" + img;
			sentContext = updateString(sentContext);
			// sentContext=JSON.parse(sentContext);
			// 在得到当前form提交的数据
			var sunContext = $("form[name='" + context + "']").serialize();
			sunContext = decodeURIComponent(sunContext, true);
			// 调用方法得到该安装配件是什么
			// TODO 检测一下是否都已经勾选
			var addAccValue = $(input).prev().prev().find(
					'input[name="addAcc"]:checked').val();
			var anzhuangpeijianAddC;
			if (addAccValue == 0) {
				anzhuangpeijianAddC = "顶装单安装码";
			} else if (addAccValue == 1) {
				anzhuangpeijianAddC = "顶装双支架";
			}
			var root2 = $(object).parent().parent().parent().next();
			var cradioFather = makeRadioFather("peijianpeijian");
			var div = $('<div class="radio-inline"></div>');
			var lableInput = $('<label>' + anzhuangpeijianAddC
					+ '<input type="hidden" name="panzhuangfangshi" value="'
					+ anzhuangpeijianAddC + '"></lable>');
			div.append(lableInput);
			cradioFather.append(div);
			var rootDiv = $(object).parent().parent().parent().parent();
			if (rootDiv.find('div[name="peijianpeijian"]').length > 0) {
				$.each(rootDiv.find('div[name="peijianpeijian"]'), function(aa,
						cc) {
					$(cc).remove();
				});
			}
			root2.after(cradioFather);

		}
	});

}

// 帘头尺寸输入
function makeLianTou(number) {
	var form = makeForm(number);
	var rootDiv = $('<div></div>');
	rootDiv.append('<h3>帘头尺寸' + number + '</h3>');
	rootDiv.append('<input type="hidden" value="' + number
			+ '" name="myNameIsHidden">');
	// 帘头安装情况
	rootDiv.append(makeTiTou("帘头安装情况:"));
	var cradioFather = makeRadioFather("liantouanzhuangqingkuang");
	cradioFather.append(makeRadio("installSite", 0, "窗帘盒",
			"liantouanzhuangchange(this)"));
	cradioFather.append(makeRadio("installSite", 1, "满墙",
			"liantouanzhuangchange(this)"));
	cradioFather.append(makeRadio("installSite", 2, "不满墙",
			"liantouanzhuangchange(this)"));
	rootDiv.append(cradioFather);
	// 帘头宽度
	rootDiv.append(makeInput("帘头宽度", "wide", "米"));
	// 帘头配件
	rootDiv.append(makeTiTou("帘头配件:"));
	rootDiv.append(makeInput("配件长度:", "saleNumber", "米"));
	form.append(rootDiv);
	form.after(makeButton("baocungailiantou", "", "baoCunLianTou(this)",
			"保存该帘头信息"));
	return form;
}
// 帘头安装情况判断 taskManage/getBuManQiangSuit.do
function liantouanzhuangchange(object) {
	var rootDiv = $(object).parent().parent().parent();
	var tese = rootDiv.find('input[name="installSite"]:checked');
	if (tese.val() == 0) {
		// 帘头配件
		var anzhuangpaijianDiv = $('<div name="peijianpeijian" style="position: relative; margin-left: 132px;margin-top:-50px"></div>')
		var anzhuang2 = $('<div class="radio-inline"></div>');
		anzhuang2
				.append('<label>粘带<input type="hidden" name="accessoriesType" value="粘带"></label>');
		anzhuangpaijianDiv.append(anzhuang2);
		$(object).parent().parent().parent().parent().find(
				'div[name="peijianpeijian"]').remove();
		$(object).parent().parent().parent().parent()
				.find('input[name="wide"]').parent().parent().next().after(
						anzhuangpaijianDiv);
	} else {
		// 帘头配件
		var anzhuangpaijianDiv = $('<div name="peijianpeijian" style="position: relative; margin-left: 132px;margin-top:-50px"></div>')
		var anzhuang2 = $('<div class="radio-inline"></div>');
		anzhuang2
				.append('<label>帘头轨<input type="hidden" name="accessoriesType" value="帘头轨"></label>');
		anzhuangpaijianDiv.append(anzhuang2);
		$(object).parent().parent().parent().parent().find(
				'div[name="peijianpeijian"]').remove();
		$(object).parent().parent().parent().parent()
				.find('input[name="wide"]').parent().parent().next().after(
						anzhuangpaijianDiv);
	}

	if (tese.val() == 0) {
		var length = rootDiv.parent().find('div[name="tupianDiv"]').length
		if (length > 0) {
			rootDiv.parent().find('div[name="tupianDiv"]').first().prev()
					.remove();
			rootDiv.parent().find('div[name="tupianDiv"]').first().remove();
		}
	} else if (tese.val() == 1) {
		var length = rootDiv.parent().find('div[name="tupianDiv"]').length
		if (length > 0) {
			rootDiv.parent().find('div[name="tupianDiv"]').first().prev()
					.remove();
			rootDiv.parent().find('div[name="tupianDiv"]').first().remove();
		}

	} else if (tese.val() == 2) {
		$.post("../taskManage/getBuManQiangSuit.do", function(data) {
			var da = new Array();
			for (var i = 0; i < data.length; i++) {
				da[i] = "http://oeilufnx2.bkt.clouddn.com/" + data[i];
			}
			rootDiv.after(makePhotoLianTou(da));
			rootDiv.after(makeTiTou("不满墙情况:"))

		}, "json");

	}
}
// 布尺寸输入
function makeBu(number, NNNN, buanzhuangweizhi) {
	var form = makeForm(number);
	var rootDiv = $('<div></div>');
	rootDiv.append('<hr>');
	rootDiv.append('<h3>' + NNNN + '尺寸' + number + '</h3>');
	rootDiv.append('<input type="hidden" value="' + number
			+ '" name="myNameIsHidden">');
	// 窗户打开方式
	rootDiv.append(makeTiTou("窗户打开方式:"));
	var cradioFather = makeRadioFather("chuanghudakaifangshi");
	cradioFather.append(makeRadio("window", 0, "平开"));
	cradioFather.append(makeRadio("window", 1, "内开"));
	cradioFather.append(makeRadio("window", 2, "外开"));
	rootDiv.append(cradioFather);
	// 布安装位置
	rootDiv.append(makeTiTou(NNNN + "安装位置:"));
	var bradioFather = makeRadioFather("buanzhuangweizhi");
	// type //0 帘头 1 纱 2 布 3 配件
	$
			.post(
					"../install/getInstallation.do",
					{
						type : 2
					},
					function(data) {
						$
								.each(
										data,
										function(i, install) {
											if (install.installSite == buanzhuangweizhi) {
												var div222 = $('<div class="radio-inline"></div>');
												var lableInput2 = $('<label><input checked="checked" type="radio" name="installSite" value="'
														+ install.installSite
														+ '" onchange="">'
														+ install.boodycount
														+ '</lable>');
												div222.append(lableInput2);
												bradioFather.append(div222);
											} else {
												bradioFather.append(makeRadio(
														"installSite",
														install.installSite,
														install.boodycount));
											}
										});
					}, "json");
	rootDiv.append(bradioFather);
	// 布配件
	rootDiv.append(makeTiTou(NNNN + "配件:"));
	var baradioFather = makeRadioFather("bupeijian");
	baradioFather.append(makeRadio("accessoriesType", 0, "罗马杆"));
	baradioFather.append(makeRadio("accessoriesType", 1, "直轨"));
	baradioFather.append(makeRadio("accessoriesType", 2, "弯轨"));
	rootDiv.append(baradioFather);
	// 装饰头
	rootDiv.append(makeTiTou("装饰头:"));
	var zhuangshitouradioFather = makeRadioFather("zhuangshitou");
	zhuangshitouradioFather.append(makeRadio("acc", 0, "标准装饰头"));
	zhuangshitouradioFather.append(makeRadio("acc", 1, "单侧小装饰头"));
	zhuangshitouradioFather.append(makeRadio("acc", 2, "双侧小装饰头"));
	rootDiv.append(zhuangshitouradioFather);
	// 安装方式(配件)
	rootDiv.append(makeTiTou("安装方式:"));
	var anZhuangaradioFather = makeRadioFather("anzhuangfangshi");
	anZhuangaradioFather.append(makeRadio("pinstallSite", 0, "顶装",
			"anzhuangfangshiChange(this)"));
	anZhuangaradioFather.append(makeRadio("pinstallSite", 1, "侧装",
			"anzhuangfangshiChange(this)"));
	rootDiv.append(anZhuangaradioFather);
	// 安装配件
	rootDiv.append(makeTiTou("安装配件:"));
	// 布宽, 布高, 杆长
	rootDiv.append(makeInput(NNNN + "宽", "wide", "米"));
	rootDiv.append(makeInput(NNNN + "高", "high", "米"));
	rootDiv.append(makeInput("杆长", "saleNumber", "米"));
	// 布制作方法
	rootDiv.append(makeTiTou(NNNN + "制作方法:"));
	var buZhiaradioFather = makeRadioFather("buzhizuofangfa");
	buZhiaradioFather.append(makeRadio("production", 0, "单开"));
	buZhiaradioFather.append(makeRadio("production", 1, "双开"));
	buZhiaradioFather.append(makeInput("其他", "productionOther", "开"));
	rootDiv.append(buZhiaradioFather);
	// 布安装位置拍照
	var buanzhuangweizhiDiv = $('<div class="form-group"></div>');
	buanzhuangweizhiDiv.append('<label class="col-sm-2 control-label">' + NNNN
			+ '安装位置拍照:</label>');
	buanzhuangweizhiDiv.append(makeUploadInput());
	rootDiv.append(buanzhuangweizhiDiv);
	// 备注信息
	rootDiv.append(makeTiTou("备注信息:"));
	rootDiv.append(makeTextArea("remark"));
	form.append(rootDiv);
	return form;
}

// 布安装位置照片改变事件

// 使用IE条件注释来判断是否IE6，通过判断userAgent不一定准确
if (document.all)
	document
			.write('<!--[if lte IE 6]><script type="text/javascript">window.ie6= true<\/script><![endif]-->');
// var ie6 = /msie 6/i.test(navigator.userAgent);//不推荐，有些系统的ie6
// userAgent会是IE7或者IE8
function inputPhotoChange(object) {
	// var file = document.getElementById(fileId);
	var file = $(object)[0];
	if ((file.files.length + $(object).parent().parent().find(
			"img[name='upImg']").length) > 4) {
		alert("您选择的图片过多, 请选择低于四张图片!");
	} else {
		// 根据选择图片的长度来形成图片
		if (window.FileReader) {// chrome,firefox7+,opera,IE10+
			for (var i = 0; i < file.files.length; i++) {
				var fr = new FileReader();
				fr.readAsDataURL(file.files[i]);
				fr.onload = function(e) {
					if ($(object).parent().parent().find(
							"div[name='tupianDiv']").length == 0) {
						var div = $('<div class="form-group" name="tupianDiv"></div>');
						$(object).parent().after(
								div.append(makeDuoUploadPhoto(132, 0,
										"duoPhoto", e.target.result)));
					} else {
						var zhengque = $('<img name="upImg" style="width: 140px;height: 178px;position: relative;margin-left: 10px;margin-top:-0px" src="'
								+ e.target.result + '" >');
						var cuowu = $('<img name="cuoPng" onclick="cuoImgClick(this)" src="../images/cuo.png" style="position: relative;margin-left: -33px;margin-top: -126px;">');
						$(object).parent().parent().find(
								"div[name='tupianDiv']").first()
								.children('div').append(zhengque);
						$(object).parent().parent().find(
								"div[name='tupianDiv']").first()
								.children('div').append(cuowu);
					}

				}
			}
		}
	}
}

// 填写布尺寸
function buClick(object) {
	// TODO 判断需要填的内容判断完了没有
	var formId = $(object).parent().parent().parent().attr("id")
	var data = $("#" + formId).data("bu_" + formId);
	if (typeof (data) == "undefined") {
		// 这是新的
		$.each($("#buMoTaiKuang").find(".modal-body>div"), function(i, from) {
			$(from).empty();
		});
		addOneNewBu($(object).parent().parent().parent().attr("id"), 11, "布");
	} else {
		$("#buMoTaiKuang").find(".modal-body>div").empty();
		addOneNewBuZhanShi($(object).parent().parent().parent().attr("id"),
				data, "布");

	}

}
// 填写纱尺寸
function shaClick(object) {
	var formId = $(object).parent().parent().parent().attr("id")
	var data = $("#" + formId).data("sha_" + formId);
	if (typeof (data) == "undefined") {
		// 这是新的
		$.each($("#shaMoTaiKuang").find(".modal-body>div"), function(i, from) {
			$(from).empty();
		});
		addOneNewBu($(object).parent().parent().parent().attr("id"), 11, "纱");
	} else {
		// 问题来了, 旧的需要把所有的信息都展示上面
		$("#shaMoTaiKuang").find(".modal-body>div").empty();
		addOneNewBuZhanShi($(object).parent().parent().parent().attr("id"),
				data, "纱");

	}
}
// 填写尺寸
function chicunClick(object) {
	var formId = $(object).parent().parent().parent().attr("id")
	var data = $("#" + formId).data("chicun_" + formId);
	if (typeof (data) == "undefined") {
		// 这是新的
		$.each($("#chicunMoTaiKuang").find(".modal-body>div"),
				function(i, from) {
					$(from).empty();
				});
		addOneNewBu(formId, 11, "");
	} else {
		// 问题来了, 旧的需要把所有的信息都展示上面
		$("#chicunMoTaiKuang").find(".modal-body>div").empty();
		addOneNewBuZhanShi($(object).parent().parent().parent().attr("id"),
				data, "");

	}
}
// 填写帘头尺寸
function lianClick(object) {
	var formId = $(object).parent().parent().parent().attr("id")
	var data = $("#" + formId).data("liantou_" + formId);
	if (typeof (data) == "undefined") {
		// 这是新的
		$.each($("#lianTouMotaiKuang").find(".modal-body>div"), function(i,
				from) {
			$(from).empty();
		});
		addOneNewLianTou(formId, 11);
	} else {
		// 问题来了, 旧的需要把所有的信息都展示上面
		$("#lianTouMotaiKuang").find(".modal-body>div").empty();
		addOneNewLianTouHuiXian(formId, data, "lianTouMotaiKuang");

	}
}

// 做备注
function makeTextArea(textName) {
	var div = $('<div class="form-group"></div>');
	var textArea = ('<textarea rows="4" cols="80" style="position: relative;margin-left: 70px;" name="'
			+ textName + '"></textarea>');
	div.append(textArea);
	return div;
}

// 做input
function makeInput(labContent, inputName, inputHou) {
	var div = $('<div class="form-group" style="position: relative;margin-top: 4px;"></div>');
	var lab = $('<label class="col-sm-2 control-label">' + labContent
			+ '</label>');
	// var input=('<input name="'+inputName+'" style="position:
	// relative;margin-top: 13px;width:100px">'+inputHou);
	var input = ('<input type="text" name="'
			+ inputName
			+ '" class="form-control" placeholder="" style="position: relative;margin-top: 13px;width:100px"><div style="position: relative;margin-top: -28px;margin-left: 109px;">'
			+ inputHou + '</div>');
	var div2 = $('<div class="col-lg-2"></div>');
	div2.append(input);
	div.append(lab);
	div.append(div2);
	return div;
}
// 做input 带value
function makeInput2(labContent, inputName, inputHou, inputValue) {
	var div = $('<div class="form-group" style="position: relative;margin-top: 4px;"></div>');
	var lab = $('<label class="col-sm-2 control-label">' + labContent
			+ '</label>');
	// var input=('<input name="'+inputName+'" style="position:
	// relative;margin-top: 13px;width:100px">'+inputHou);
	var input = ('<input type="text" name="'
			+ inputName
			+ '" class="form-control" value="'
			+ inputValue
			+ '" placeholder="" style="position: relative;margin-top: 13px;width:100px"><div style="position: relative;margin-top: -28px;margin-left: 109px;">'
			+ inputHou + '</div>');
	var div2 = $('<div class="col-lg-2"></div>');
	div2.append(input);
	div.append(lab);
	div.append(div2);
	return div;
}
// 做题头 //安装配件也可以在这里
function makeTiTou(content) {
	var div = $('<div class="form-group"></div>');
	var lable = ('<label class="col-sm-2 control-label">' + content + '</label>');
	return div.append(lable);
}
// 做radio父div
function makeRadioFather(name) { // left:315
	return $('<div name="'
			+ name
			+ '" style="position: relative; margin-left: 132px;margin-top:-50px"></div>');
}
// 做radio
function makeRadio(name, value, content, change) {
	var div = $('<div class="radio-inline"></div>');
	var lableInput = $('<label><input type="radio" name="' + name + '" value="'
			+ value + '" onchange="' + change + '">' + content + '</lable>');
	return div.append(lableInput);
}
// 做radio 带选择
function makeRadio2(name, value, content, change, checked) {
	var div = $('<div class="radio-inline"></div>');
	var lableInput = $('<label><input type="radio" ' + checked + ' name="'
			+ name + '" value="' + value + '" onchange="' + change + '">'
			+ content + '</lable>');
	return div.append(lableInput);
}

// 做按钮
function makeButton(id, tarId, click, content) {
	var div = $('<div style="position:relative;margin-left: 195px;"></div>');
	div
			.append('<button style="position: relative;margin-left: 126px;" class="btn btn-success" id="'
					+ id
					+ '" type="button" onclick="'
					+ click
					+ '" data-toggle="modal" data-target="#'
					+ tarId
					+ '" >'
					+ content + '</button><br>');
	return div;
}
function makeButton2(id, click, content) {
	var div = $('<div style="position:relative;margin-left: 195px;margin-top: 62px;"></div>');
	div
			.append('<button style="position: relative;margin-left: 284px;margin-top: -57px;" class="btn btn-success" id="'
					+ id
					+ '" type="button" onclick="'
					+ click
					+ '" >'
					+ content + '</button><br>');
	return div;
}
function makeButton3(id, click, content) {
	var div = $('<div style="position:relative;margin-left: 264px;margin-top: 61px;"></div>');
	div
			.append('<button style="position: relative;margin-left: 284px;margin-top: -57px;" class="btn btn-success" id="'
					+ id
					+ '" type="button" onclick="'
					+ click
					+ '" >'
					+ content + '</button><br>');
	return div;
}
// 删除按钮
function makeButton4(id, click, content) {
	var div = $('<div style="position:relative;margin-left: 195px;"></div>');
	div
			.append('<button style="position: relative;margin-left: 471px;margin-top: -92px;" class="btn btn-danger" id="'
					+ id
					+ '" type="button" onclick="'
					+ click
					+ '" >'
					+ content + '</button><br>');
	return div;
}
function makeButton5(id, click, content) {
	var div = $('<div style="position:relative;margin-left: 257px;margin-top: 141px;"></div>');
	div
			.append('<button style="position: relative;margin-left: 427px;margin-top: -216px;" class="btn btn-danger" id="'
					+ id
					+ '" type="button" onclick="'
					+ click
					+ '" >'
					+ content + '</button><br>');
	return div;
}
// 做form
function makeForm(number) {
	return $('<form name="defaultForm_' + number
			+ '" class="form-horizontal" method="post"></form>');
}
// makeFrom
function makeFormId(number) {
	return $('<form id="defaultForm_' + number
			+ '" class="form-horizontal" method="post"></form>');
}
// 增加新的窗户
function addOneNewWindow() {
	var a = 0;
	$.each($("#rootDiv>form").find('h3'), function(b, inx) {
		a++
	});
	$("#rootDiv").append(addNewWindow(a));
	$("#rootDiv").append(
			makeButton2("baocungaichuanghuxinxi", "baocunchuanghu(this)",
					"保存该窗帘信息"));
	$('#rootDiv').append(
			makeButton4("deleteChuanghuxinxi", "deleteChuangHu(this)",
					"删除该窗帘信息"));
}
// 添加新的帘头尺寸 添加新帘头
function addOneNewLianTou(formName, object) {
	if (formName == 11) {
		// 这是从弹窗界面发过来的
		var rootDiv = $(object).prev('div');
		// 这是从弹出界面发送过来的
		$.each(rootDiv.find('[name="hiddenInput"]'), function(ii, input) {
			if (ii == 0) {
				formName = $(input).val();
			}
		});

		$.each($("#lianTouMotaiKuang").find(".modal-body>div"), function(i,
				from) {
			var a = 0;
			$.each($("#lianTouMotaiKuang").find("h3"), function(w, inx) {
				a++;
			});
			$(from).append(makeLianTou(a + 1));
			$(from).append(
					makeButton5("deletegaibu", "deleteBu(this)", "删除该帘头信息"));
			// 存进来form的名字
			$(from).append(
					'<input type="hidden" name="hiddenInput" value="'
							+ formName + '">');
		});
		// 把上面提交的所有信息都保存一下
		baocunLian(rootDiv, "liantou_");
	} else {
		// 这是那个填写帘头尺寸
		$.each($("#lianTouMotaiKuang").find(".modal-body>div"), function(i,
				from) {
			var a = 0;
			$.each($("#lianTouMotaiKuang").find("h3"), function(w, inx) {
				a++;
			});
			$(from).append(makeLianTou(a + 1));
			$(from).append(
					makeButton5("deletegaibu", "deleteBu(this)", "删除该帘头信息"));
			// 存进来form的名字
			$(from).append(
					'<input type="hidden" name="hiddenInput" value="'
							+ formName + '">');
		});
	}
}
// 添加新的布尺寸
function addOneNewBu(formName, object, NNNN) {
	var motaiId;
	var baocunContext;
	if (NNNN == "布") {
		motaiId = "buMoTaiKuang";
		baocunContext = "bu_";
	} else if (NNNN == "") {
		motaiId = "chicunMoTaiKuang";
		baocunContext = "chicun_";
	} else if (NNNN == "纱") {
		motaiId = "shaMoTaiKuang";
		baocunContext = "sha_";
	}
	if (formName == 11) {
		var rootDiv = $(object).prev('div');
		// 这是从弹出界面发送过来的
		$.each(rootDiv.find('[name="hiddenInput"]'), function(ii, input) {
			if (ii == 0) {
				formName = $(input).val();
			}
		});

		$.each($("#" + motaiId).find(".modal-body>div"), function(i, from) {
			var a = 0;
			$.each($("#" + motaiId).find("h3"), function(w, inx) {
				a++;
			});
			$(from).append(makeBu(a + 1, NNNN));
			$(from).append(
					makeButton5("deletegaibu", "deleteBu(this)", "删除该布信息"));
			// 存进来form的名字
			$(from).append(
					'<input type="hidden" name="hiddenInput" value="'
							+ formName + '">');
		});
		// 把上面提交的所有信息都保存一下
		baocun(rootDiv, baocunContext);
	} else {
		$.each($("#" + motaiId).find(".modal-body>div"), function(i, from) {
			var a = 0;
			$.each($("#" + motaiId).find("h3"), function(w, inx) {
				a++;
			});
			$(from).append(makeBu(a + 1, NNNN));
			$(from).append(
					makeButton5("deletegaibu", "deleteBu(this)", "删除该布信息"));
			// 存进来form的名字
			$(from).append(
					'<input type="hidden" name="hiddenInput" value="'
							+ formName + '">');
		});

	}

}
// 把帘头吃存回显 第一个表格的id 数据 帘头模态框id
function addOneNewLianTouHuiXian(formName, data, motaiId) {
	var rootDiv = $("#" + motaiId).find(".modal-body>div");
	rootDiv.empty();
	for (var i = 0; i < data.length; i++) {
		var formContext = data[i];
		// 把帘头生成
		rootDiv.append(makeLianTou(i + 1));
		rootDiv.append(makeButton5("deletegaibu", "deleteBu(this)", "删除该帘头信息"));
		// 存进来form的名字
		rootDiv.append('<input type="hidden" name="hiddenInput" value="'
				+ formName + '">');
		// 数据填充 installation
		var formObject = rootDiv.find('form[name="defaultForm_' + (i + 1)
				+ '"]');
		// wide
		formObject.find('input[name="wide"]').first().val(formContext.wide);
		// 配件长度
		formObject.find('input[name="saleNumber"]').first().val(
				formContext.saleNumber);
		// 帘头安装情况
		$.each(formObject.find('input[name="installSite"]'),
				function(aa, input) {
					if ($(input).val() == formContext.installSite) {
						$(input).attr({
							checked : "checked"
						});
					}
				});

		// 判断一下, 需不需要
		if (formContext.installSite == 2) {
			// 图片回显
			var anzhuangqingkuang = formObject.find(
					'div[name="liantouanzhuangqingkuang"]').first();
			// 这只是展示的
			var tupianDiv = $('<div class="form-group" name="tupianDiv"></div>');
			var div2 = $('<div style="position: relative;margin-top: 20px;"></div>');
			for (var ii = 0; ii < formContext.imgs.length; ii++) {
				if (ii == 0) { // onmouseout="duiImgOut(this)"
					div2
							.append('<img name="upImg" onmouseover="duiImgMouse(this)" onclick="duiImgClick(this)" onmouseout="duiImgOut(this)" style="width: 140px;height: 178px;position: relative;margin-left: 132px;margin-top:-0px" src="'
									+ formContext.imgs[ii]
									+ '" name="duoPhoto">')
				} else {
					// 判断是不是
					if (formContext.imgs[ii] == "../images/dui.png") {
						div2
								.append('<img name="duiPng2" src="../images/dui.png" style="position: relative;margin-left: -13px;margin-top: -150px;">');
					} else {
						div2
								.append('<img name="upImg" onmouseover="duiImgMouse(this)" onclick="duiImgClick(this)" onmouseout="duiImgOut(this)" style="width: 140px;height: 178px;position: relative;margin-left: 10px;margin-top:-0px" src="'
										+ formContext.imgs[ii]
										+ '" name="duoPhoto">')
					}
				}
			}
			tupianDiv.append(div2);
			anzhuangqingkuang.after(tupianDiv);
			anzhuangqingkuang.after(makeTiTou("不满墙情况:"))
		} else {

		}
		if (formContext.installSite == 0) {
			// 帘头配件
			var anzhuangpaijianDiv = $('<div name="peijianpeijian" style="position: relative; margin-left: 132px;margin-top:-50px"></div>')
			var anzhuang2 = $('<div class="radio-inline"></div>');
			anzhuang2
					.append('<label>粘带<input type="hidden" name="accessoriesType" value="粘带"></label>');
			anzhuangpaijianDiv.append(anzhuang2);
			formObject.find('div[name="peijianpeijian"]').remove();
			formObject.find('input[name="wide"]').parent().parent().next()
					.after(anzhuangpaijianDiv);
		} else {
			// 帘头配件
			var anzhuangpaijianDiv = $('<div name="peijianpeijian" style="position: relative; margin-left: 132px;margin-top:-50px"></div>')
			var anzhuang2 = $('<div class="radio-inline"></div>');
			anzhuang2
					.append('<label>帘头轨<input type="hidden" name="accessoriesType" value="帘头轨"></label>');
			anzhuangpaijianDiv.append(anzhuang2);
			formObject.find('div[name="peijianpeijian"]').remove();
			formObject.find('input[name="wide"]').parent().parent().next()
					.after(anzhuangpaijianDiv);
		}

	}
}

// 把布尺寸信息都展示上去
function addOneNewBuZhanShi(formName, data, NNNN) {
	var motaiId;
	if (NNNN == "布") {
		motaiId = "buMoTaiKuang";
	} else if (NNNN == "纱") {
		motaiId = "shaMoTaiKuang";
	} else if (NNNN == "") {
		motaiId = "chicunMoTaiKuang";
	}

	var rootDiv = $("#" + motaiId).find(".modal-body>div");
	rootDiv.empty();
	for (var i = 0; i < data.length; i++) {
		var formContext = data[i];

		// 生成
		rootDiv.append(makeBu(i + 1, NNNN, formContext.installSite));
		rootDiv.append(makeButton5("deletegaibu", "deleteBu(this)", "删除该布信息"));
		// 存进来form的名字
		rootDiv.append('<input type="hidden" name="hiddenInput" value="'
				+ formName + '">');
		// TODO 这个要根据条件判断, 如果应该显示那就显示
		// 得到顶装侧装位置, 然后 div anzhuangfangshi
		// 判断应该弄顶装
		if (formContext.addAcc != null) {
			var anzhuangpeijaindiv = rootDiv.find(
					'form[name="defaultForm_' + (i + 1) + '"]').find(
					'div[name="anzhuangfangshi"]');
			var cradioFather = makeRadioFather("peijianpeishian");
			cradioFather.append(makeRadio("addAcc", 0, "顶装单安装码",
					"peijianAccChange(this)"));
			cradioFather.append(makeRadio("addAcc", 1, "顶装双支架",
					"peijianAccChange(this)"));
			anzhuangpeijaindiv.after(makeTiTou("配件配饰安装:"));
			anzhuangpeijaindiv.next("div").after(cradioFather);
		}
		// 安装配件
		var anzhuangpaijianDiv = $('<div name="peijianpeijian" style="position: relative; margin-left: 132px;margin-top:-50px"></div>')
		var anzhuang2 = $('<div class="radio-inline"></div>');
		anzhuang2.append('<label>' + formContext.panzhuangfangshi
				+ '<input type="hidden" name="panzhuangfangshi" value="'
				+ formContext.panzhuangfangshi + '"></label>');
		anzhuangpaijianDiv.append(anzhuang2);
		var form = rootDiv.find('form[name="defaultForm_' + (i + 1) + '"]')
				.first();
		form.find('input[name="wide"]').first().parent().parent().before(
				anzhuangpaijianDiv);
		// input
		var arrStr2 = new Array("wide", "high", "saleNumber", "productionOther");
		var valStr = new Array(formContext.wide, formContext.high,
				formContext.saleNumber, formContext.productionOther);
		for (var te = 0; te < arrStr2.length; te++) {
			form.find('input[name="' + arrStr2[te] + '"]').val(valStr[te]);
		}
		// 备注
		form.find('textArea[name="remark"]').val(formContext.remark);
		// 图片 inputPhotoChange(this)
		if (formContext.imgs.length > 0 && formContext.imgs != null) {
			form.find('div[name="buzhizuofangfa"]').first().next().children(
					"div").append(makePhotoHuiXian(formContext.imgs))
		}
		// checked //窗户打开方式 制作方法 配件类型 装饰头 安装方式 安装位置 选项
		var arrStr = new Array("window", "production", "accessoriesType",
				"acc", "pinstallSite", "installSite", "addAcc");
		var valueInt = new Array(formContext.window, formContext.production,
				formContext.accessoriesType, formContext.acc,
				formContext.pinstallSite, formContext.installSite,
				formContext.addAcc);
		for (var te = 0; te < arrStr.length; te++) {
			$.each(form.find('input[name="' + arrStr[te] + '"]'), function(aa,
					input) {
				var value = valueInt[te];
				if ($(input).val() == value) {
					$(input).attr({
						checked : "checked"
					});
				}
			});
		}

	}

}
// zuo帘头
function makePhotoLianTou(data) {
	var rootDiv = $('<div class="form-group" name="tupianDiv"></div>');
	var div2 = $('<div style="position: relative;margin-top: 20px;"></div>');
	// 这只是展示的
	for (var i = 0; i < data.length; i++) {
		if (i == 0) { // onmouseout="duiImgOut(this)"
			div2
					.append('<img name="upImg" onmouseover="duiImgMouse(this)" onclick="duiImgClick(this)" onmouseout="duiImgOut(this)" style="width: 140px;height: 178px;position: relative;margin-left: 132px;margin-top:-0px" src="'
							+ data[i] + '" name="duoPhoto">')
		} else {
			div2
					.append('<img name="upImg" onmouseover="duiImgMouse(this)" onclick="duiImgClick(this)" onmouseout="duiImgOut(this)" style="width: 140px;height: 178px;position: relative;margin-left: 10px;margin-top:-0px" src="'
							+ data[i] + '" name="duoPhoto">')
		}
	}
	rootDiv.append(div2);
	return rootDiv;
}
// 做图片记忆回显 data 图片数组
function makePhotoHuiXian(data) {
	// 判断选对还是选击叉
	var rootDiv = $('<div class="form-group" name="tupianDiv"></div>');
	var div2 = $('<div style="position: relative;margin-top: 20px;"></div>');
	for (var i = 0; i < data.length; i++) {
		if (i == 0) {
			div2
					.append('<img name="upImg" style="width: 140px;height: 178px;position: relative;margin-left: 132px;margin-top:-0px" src="'
							+ data[i] + '" name="duoPhoto">')
			div2
					.append('<img name="cuoPng" onclick="cuoImgClick(this)" src="../images/cuo.png" style="position: relative;margin-left: -33px;margin-top: -126px;">');
		} else {
			div2
					.append('<img name="upImg" style="width: 140px;height: 178px;position: relative;margin-left: 10px;margin-top:-0px" src="'
							+ data[i] + '" name="duoPhoto">')
			div2
					.append('<img name="cuoPng" onclick="cuoImgClick(this)" src="../images/cuo.png" style="position: relative;margin-left: -33px;margin-top: -126px;">');
		}
	}
	rootDiv.append(div2);
	return rootDiv;
}

// 做单个图片上传 外面用的
function makeOnlyUploadPhoto(name) {
	var rootDiv = $('<div name="'
			+ name
			+ '" class="fileupload fileupload-new" data-provides="fileupload" style="position: relative;margin-left: 211px;"></div>');
	var div1 = $('<div class="fileupload-new thumbnail" style="width: 200px; height: 150px;"></div>');
	var div11 = $('<img src="../static/images/noImage.png" alt="" name="photo">');
	div1.append(div11);
	var div2 = ('<div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 200px; max-height: 150px; line-height: 10px;"></div>');
	var div3 = $('<div></div>');
	var span = $('<span class="btn btn-default btn-file"></span>');
	span
			.append('<span class="fileupload-new"><i class="fa fa-paper-clip"></i>选择图片</span>');
	span
			.append('<span class="fileupload-exists"><i class="fa fa-undo"></i>更换图片</span>');
	span.append('<input type="file" class="default">');
	div3.append(span);
	div3
			.append('<a href="#" class="btn btn-danger fileupload-exists" data-dismiss="fileupload"><i class="fa fa-trash"></i>删除图片</a>');
	rootDiv.append('<input type="hidden">');
	rootDiv.append(div1);
	rootDiv.append(div2);
	rootDiv.append(div3);
	return rootDiv;

}
// 做多个图片上传
function makeDuoUploadPhoto(left, top, name, src) {
	var rootDiv = $('<div style="position: relative;margin-top: 20px;"></div>');
	rootDiv
			.append('<img name="upImg" style="width: 140px;height: 178px;position: relative;margin-left: '
					+ left
					+ 'px;margin-top:-'
					+ top
					+ 'px" src="'
					+ src
					+ '" name="' + name + '" >');
	rootDiv
			.append('<img name="cuoPng" onclick="cuoImgClick(this)" src="../images/cuo.png" style="position: relative;margin-left: -33px;margin-top: -126px;">');
	return rootDiv;
}
// 做上传图片的input
function makeUploadInput() {
	var rootDiv = $('<div style="position: relative;margin-top: 18px;"></div>');
	var span = $('<span class="btn btn-default btn-file"></span>');
	span
			.append('<span class="fileupload-new"><i class="fa fa-paper-clip"></i>选择图片</span>');
	span
			.append('<input type="file" class="default" multiple="multiple" onchange="inputPhotoChange(this)">');
	rootDiv.append(span);
	return rootDiv;

}
// 字符串工具类
function updateString(data) {
	data = data.replace(/&/g, "\",\"");
	data = data.replace(/=/g, "\":\"");
	data = "{\"" + data + "\"}";
	return data;
}

// 检验表单是否添加完成
function checkForm(formObject) {
	$(formObject).find();
}
// 操作成功之后提示
function success(text) {
	$("#alerts")
			.html(
					"<div  style='text-align: center; display:no;' class='alert alert-success alert-dismissable'><strong>"
							+ text + "</strong></div>");
	$("#menus").click();
	setTimeout(close, 2000);
}
// 提示关闭
function close() {
	$('#mmm').modal('hide');
}

// 操作失败之后提示

function fail(text) {
	$("#alerts")
			.html(
					"<div  style='text-align: center; display:no;' class='alert alert-success alert-dismissable'><strong>"
							+ text + "</strong></div>");
	$("#menus").click();

}
function myfresh() {
	window.location.href = window.location.href;
}
// 弹出框帘头保存 帘头保存
function clickLianBaoCun(object, cName) {
	var rootDiv = $(object).parent().prev().find('div').first();
	baocunLian(rootDiv, cName);
}

// 弹出框 保存按钮
function clickBaoCun(object, NNNN) {
	var motaiId;
	if (NNNN == "布") {
		motaiId = "bu_";
	} else if (NNNN == "纱") {
		motaiId = "sha_";
	} else if (NNNN == "") {
		motaiId = "chicun_";
	}
	var rootDiv = $(object).parent().prev().find('div').first();
	baocun(rootDiv, motaiId);
}
// 保存信息的通用方法
function baocun(rootDiv, cunName) {
	var allform = rootDiv.find("form");
	var arr = new Array();
	var oneFormId;
	$.each(rootDiv.find('input[name="hiddenInput"]'), function(ii, input) {
		if (ii == 0) {
			oneFormId = $(input).val();
		}
	});
	var oneForm = $("#" + oneFormId);
	$.each(allform, function(i, form) {
		var formContext = $(form).serialize();
		formContext = decodeURIComponent(formContext, true);
		var imgg = new Array();
		$.each($(form).find('img[name="upImg"]'), function(iii, img) {
			imgg[iii] = $(img).attr("src");
		});
		formContext = updateString(formContext);
		formContext = JSON.parse(formContext);
		formContext.imgs = imgg;
		arr[i] = formContext;
	});
	oneForm.data(cunName + oneFormId, arr);
}
// 帘头保存信息
function baocunLian(rootDiv, cunName) {
	var allform = rootDiv.find("form");
	var arr = new Array();
	var oneFormId = rootDiv.find('input[name="hiddenInput"]').first().val();
	var oneForm = $("#" + oneFormId);
	$.each(allform, function(i, form) {
		var formContext = $(form).serialize();
		formContext = decodeURIComponent(formContext, true);
		var imgg = new Array();

		$.each($(form).find('img'), function(iii, img) {
			imgg[iii] = $(img).attr("src");
		});
		formContext = updateString(formContext);
		formContext = JSON.parse(formContext);
		formContext.imgs = imgg;
		arr[i] = formContext;
	});
	oneForm.data(cunName + oneFormId, arr);
}

// 图片删除按钮
function cuoImgClick(object) {
	var indexImg = $(object).index();
	var leng = $(object).parent().parent().find("img[name='upImg']").length;
	if (leng == 1) {
		$(object).parent().parent().remove();
	} else {
		if (indexImg == 1) {
			$(object)
					.next()
					.attr(
							{
								style : "width: 140px;height: 178px;position: relative;margin-left: 132px;margin-top:-0px"
							});
			$(object).prev().remove();
			$(object).remove();

		} else {
			$(object).prev().remove();
			$(object).remove();
		}
	}
}
// 图片出现对号
function duiImgMouse(object) {
	var name = $(object).next().attr("name");
	if (name == "duiPng2") {

	} else {
		var img = $('<img name="duiPng" src="../images/dui.png" style="position: relative;margin-left: -13px;margin-top: -150px;">');
		var imgcount = $(object).parent().find('img[name="duiPng"]');
		$.each(imgcount, function(i, imgg) {
			$(imgg).remove();
		});
		$(object).after(img);
	}

}
// 对号图片的点击事件
function duiImgClick(object) {
	var img = $('<img name="duiPng2" src="../images/dui.png" style="position: relative;margin-left: -13px;margin-top: -150px;">');
	var index = $(object).index();
	$.each($(object).parent().find('img[name="duiPng"]'), function(ii, imgg) {
		$(imgg).remove();
	});
	if ($(object).parent().find('img[name="duiPng2"]').length > 0) {
		$.each($(object).parent().find('img[name="duiPng2"]'), function(ii,
				imgg) {
			$(imgg).remove();
		});
	}
	$(object).after(img);
}

// 图片离开把对号去掉
function duiImgOut(object) {
	$.each($(object).parent().find('img[name="duiPng"]'), function(ii, imgg) {
		$(imgg).remove();
	});
}

// 取消订单
function quitIndentModalOpen(indentId, type,customerId){
	// 获取
	$.ajax({
		url : projectName+'/indent/showSubMoney',
		type : 'post',
		dataType : 'text',
		data : {
			indentId : indentId,
		},
		success : function(data) {
			var message = "确认要取消订单吗？";
			if (data != 0.0) {
				message = "取消订单需扣除" + data + "元，确认要取消订单吗？";
			}
			Ewin.confirm({
				message : message
			}).on(function(e) {
				if (!e) {
					return;
				}
				$.ajax({
					url :projectName+'/indent/quitIndent',
					type : 'post',
					dataType : 'JSON',
					data : {
						indentId : indentId,
						type : type,
						merchantId:customerId,
						subMoney : data
					},
					success : function(data) {
						if (data.status == 0) {
							toastr.success("取消成功！");
							//$("#toMoney span").html(data.data);
							//改变余额
							$("#wallet").find("span").first().html(data.data);
							$("button[name='refresh']").trigger("click");
						} else {
							toastr.error("取消失败！");
						}
					}
				});
			});
		}
	})
}
